﻿using MongoDB.Driver;
using Server.Database;
using Server.Resource;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Server.Business
{
    public class LogService
    {
        private static MongoDatabase _database;
        private static MongoCollection<LogDB> _logArray;

        private static MongoCollection<LogDB> LogArray
        {
            get
            {
                if (_logArray == null)
                    _logArray = Database.GetCollection<LogDB>("LogDB");
                return _logArray; 
            }
        }

        private static MongoDatabase Database
        {
            get
            {
                if (_database == null)
                {
                    MongoClient client = new MongoClient(ServerConfig.Singleton.Database);
                    MongoServer server = client.GetServer();
                    _database = server.GetDatabase("zcdb");
                }
                return _database;
            }
        }

        public static void Log(LogDB log)
        {
            LogArray.Insert(log);
        }

        public static IEnumerable<LogDB> GetLogs()
        {
            return LogArray.FindAll();
        }
    }
}
